<template>
  <div class="login-container">
    <div class="login-card">
      <div class="login-header">
        <h1>🔗 Link Chat</h1>
        <p>实时互动聊天应用</p>
      </div>

      <form @submit.prevent="handleSubmit" class="login-form">
        <div class="form-group">
          <label for="username">输入你的昵称</label>
          <input
            id="username"
            v-model="usernameInput"
            type="text"
            placeholder="请输入昵称"
            maxlength="20"
            required
          />
        </div>

        <button type="submit" class="login-button">
          进入聊天室
        </button>
      </form>

      <div class="login-footer">
        <p>支持多人实时互动 • Vue 3 + Go + WebSocket</p>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'

const emit = defineEmits(['login'])
const usernameInput = ref('')

const handleSubmit = () => {
  if (usernameInput.value.trim()) {
    emit('login', usernameInput.value.trim())
  }
}
</script>

<style scoped>
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.login-card {
  background: white;
  border-radius: 20px;
  padding: 50px 40px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  min-width: 400px;
  max-width: 500px;
}

.login-header {
  text-align: center;
  margin-bottom: 40px;
}

.login-header h1 {
  font-size: 2.5rem;
  color: #667eea;
  margin-bottom: 10px;
  font-weight: 700;
}

.login-header p {
  font-size: 1rem;
  color: #666;
}

.login-form {
  margin-bottom: 30px;
}

.form-group {
  margin-bottom: 25px;
}

.form-group label {
  display: block;
  margin-bottom: 10px;
  font-weight: 600;
  color: #333;
  font-size: 0.95rem;
}

.form-group input {
  width: 100%;
  padding: 14px 18px;
  font-size: 1rem;
  border-radius: 10px;
  border: 2px solid #e0e0e0;
}

.login-button {
  width: 100%;
  padding: 16px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  font-size: 1.1rem;
  font-weight: 600;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.login-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 25px rgba(102, 126, 234, 0.4);
}

.login-footer {
  text-align: center;
  padding-top: 20px;
  border-top: 1px solid #e0e0e0;
}

.login-footer p {
  font-size: 0.85rem;
  color: #999;
}
</style>
